﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Web.Script.Serialization;

namespace M.Dao.Client.Core
{
    public class SchemaAccess : HttpServiceBase, ISchemaAccess 
    {
        private string _url = string.Empty;

        public string Url
        {
            get
            {
                return _url;
            }
            set
            {
                _url = value;
            }
        }

        public SchemaAccess(string url)
        {   
            this.Url = url;
        }
        
        public DataResult<T> Tables<T>(string db, string accessToken)
        {
            string writeUrl = Path.Combine(this.Url, "schema/Tables");

            KeyValuePair<string, string> kvDB = new KeyValuePair<string, string>("DB", db);
            KeyValuePair<string, string> kvAT = new KeyValuePair<string, string>("AT", accessToken);

            string httpResult = this.Post(writeUrl, string.Empty, kvDB, kvAT);

            var result = Newtonsoft.Json.JsonConvert.DeserializeObject<DataResult<T>>(httpResult);

            return result;
        }
    }
}
